package com.net.tkc.pro.tool;

import com.net.tkc.pro.tool.BaiDu.OCR.HttpUtil;
import net.sf.json.JSONObject;
//import org.json.JSONObject;
import org.springframework.stereotype.Component;


import java.net.URLEncoder;
@Component//注入Springboot框架
public class APITool {
    public static final String APPKEY = "dc8c3924a52ad3bb";// 你的appkey
    public static final String URL = "https://api.binstd.com/iqa/query";

    public static String Get(String question) throws Exception {
        String result = null;
        String url = URL + "?appkey=" + APPKEY + "&question=" + URLEncoder.encode(question, "utf-8");
        String flag="";
        try {
            result = HttpUtil.sendGet(url, "utf-8");
            JSONObject json = JSONObject.fromObject(result);
            if (json.getInt("status") != 0) {
                System.out.println(json.getString("msg"));
            } else {
                JSONObject resultarr = json.optJSONObject("result");
                String type = resultarr.getString("type");
                String content = resultarr.getString("content");
                String relquestion = resultarr.getString("relquestion");
                flag=type + " " + content + " " + relquestion;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }
}
